<?php

class PinglunModel extends Model {
	
	public function get_primary_key() {
		return $this->primary_key = 'id';
	}
	public function get_paisong_list(){
		
	}

    public function set($id, $data) {
        if ($id) {
            $this->db->where('member_id', $id);
            $this->db->update('shop_comment', $data);
            return $id;
        }
        $return = $this->db->insert('shop_comment', $data);
        if ($return) return $return;
        return false;
    }

    public function set2($id, $data) {
        if ($id) {
            $this->db->where('id', $id);
            $this->db->update('shop_comment', $data);
            return $id;
        }
        $return = $this->db->insert('shop_comment', $data);
        if ($return) return $return;
        return false;
    }
	
	public function del($id) {
        $this->db->delete('shop_comment',array('id'=>$id));
        return $id;
	}
	
	public function get_one($where){
		$sql = "select * from ".$this->prefix . "shop_comment where $where";
		return $this->db->query($sql)->row_array();
	}

    public function get_num($where){
            $sql = "select count(id) as total from ".$this->prefix . "shop_comment
					where $where";
            $res = $this->db->query($sql)->row_array();
            return $res['total'];
    }

    //后台
    public function get_admin_list($where,$order,$limit,$ifcount=false){
        if($ifcount){
            $sql = "select count(m.id) as total from ".$this->prefix . "shop_comment as m
            left join ".$this->prefix."member as me on m.member_id = me.id
            left join ".$this->prefix."content_1 as c on m.pingjia_id = c.id
					where $where";
            $res = $this->db->query($sql)->row_array();
            return $res['total'];
        }
        $sql = "select m.*,me.name,me.username,c.title from ".$this->prefix . "shop_comment as m
            left join ".$this->prefix."member as me on m.member_id = me.id
            left join ".$this->prefix."content_1 as c on m.pingjia_id = c.id
		        where $where order by $order limit $limit";
        $res = $this->db->query($sql)->result_array();
        return $res;
    }

    //前台
    public function get_all_list($where,$order,$limit,$ifcount=false){
        if($ifcount){
            $sql = "select count(m.id) as total from ".$this->prefix . "shop_comment as m
            left join ".$this->prefix."member as me on m.member_id = me.id
            left join ".$this->prefix."content_1 as c on m.pingjia_id = c.id
					where $where";
            $res = $this->db->query($sql)->row_array();
            return $res['total'];
        }
        $sql = "select m.*,me.name,me.logo,me.username,c.title,c.thumb as img,c.price from ".$this->prefix . "shop_comment as m
            left join ".$this->prefix."member as me on m.member_id = me.id
            left join ".$this->prefix."content_1 as c on m.pingjia_id = c.id
		        where $where order by $order limit $limit";
        $res = $this->db->query($sql)->result_array();
        return $res;
    }

}